package com.app.library.utils

import android.graphics.Color
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.RelativeLayout
import android.widget.TextView
import com.app.library.R
import com.blankj.utilcode.util.ToastUtils
import com.blankj.utilcode.util.Utils

object CustomToast {
    fun showShort(res: Int) {
        showShort(Utils.getApp().getString(res))
    }

    fun showShort(content: String) {
        val viewToast = getToastView(content)
        ToastUtils()
            .setGravity(Gravity.CENTER, 0, 0)
            .show(viewToast)
    }

    fun showLong(res: Int) {
        showLong(Utils.getApp().getString(res))
    }

    fun showLong(content: String) {
        val viewToast = getToastView(content)
        ToastUtils()
            .setGravity(Gravity.CENTER, 0, 0)
            .setDurationIsLong(true)
            .show(viewToast)
    }

    fun showLightShort(content: String) {
        val viewToast = getLightToastView(content)
        ToastUtils()
            .setGravity(Gravity.CENTER, 0, 0)
            .show(viewToast)
    }

    private fun getToastView(content: String): View {
        val viewToast = LayoutInflater.from(Utils.getApp()).inflate(R.layout.layout_toast, null)
        val layoutContent = viewToast.findViewById<RelativeLayout>(R.id.rl_toast_bg)
        layoutContent.setBackgroundResource(R.drawable.bg_toast_white)
        val textView = viewToast.findViewById<TextView>(R.id.tv_toast)
        textView.setTextColor(Color.parseColor("#000000"))
        textView.text = content
        return viewToast
    }

    private fun getLightToastView(content: String): View {
        val viewToast = LayoutInflater.from(Utils.getApp()).inflate(R.layout.layout_toast, null)
        val textView = viewToast.findViewById<TextView>(R.id.tv_toast)
        textView.text = content
        return viewToast
    }
}